package main;

import java.io.IOException;
import java.util.HashMap;

import org.newdawn.slick.BasicGame;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;

import state.AuthorsState;
import state.PlayState;
import state.StartState;
import state.State;
import state.TheEndState;

import constans.Flag;
import constans.Global;
import constans.ResourceManager;

public class Game extends BasicGame {

	static State presentState;
    public Game(String title) {
		super(title);
    }	
    public void render(GameContainer container, Graphics g) throws SlickException {	
		presentState.render(container, g);		
	}
	public void init(GameContainer container) throws SlickException {
		//ladowanie zasobow
		if (!Global.RESOURCES_INITIATED)
		{
			try {
				ResourceManager.loadResources("data/resources.xml");
			} catch (IOException e) {
				e.printStackTrace();
			}
			Global.RESOURCES_INITIATED = true;
		}
		setState(Flag.startState, 0);
	}	
	public void update(GameContainer container, int delta)
			throws SlickException {
		
		presentState.update(container, delta);	
	}
	public static void setState(int id, int p)
	{
		switch(id)
		{
			case Flag.playState:
				presentState = new PlayState();
				break;
			case Flag.startState:
				presentState = new StartState();
				break;
			case Flag.authorsState:
				presentState = new AuthorsState();
				break;
			case Flag.theEndState:
				presentState = new TheEndState(p);
				break;	
			
		}
	}

}